package com.my.order.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.alibaba.dubbo.rpc.cluster.loadbalance.RoundRobinLoadBalance;
import com.my.common.domain.UserAddress;
import com.my.common.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Arrays;
import java.util.List;

@Controller
@RequestMapping("/order")
public class OrderController {

    //@Autowired
    @Reference(loadbalance = RoundRobinLoadBalance.NAME, //负载均衡策略：轮询
            //url = "127.0.0.1:20880", //dubbo直连
            check = false , timeout = 3000, retries = 3)//dubbo远程引用暴露的接口，相当于远程版的@Autowired
    UserService userService;

    @RequestMapping("/getList")
    @ResponseBody
    public List<UserAddress> getList(Integer uid){
        System.out.println("用户id="+uid);
        List<UserAddress> list = userService.getList(uid);
        System.out.println("远程调用完成");
        return list;
    }

}
